<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
 
      <div>
        用户：<input class="user" type="text" name='user' value=''>
      </div>
      <div>
        密码：<input class="password" type="password" name='psd' value=''>
      </div>
        
        <div class="act">
            注册
        </div>
        <div class="login">
            登陆
        </div>
       <script>
         let user = document.querySelector('.act');
         let loginValue = document.querySelector('.login');


         user.onclick = function (e){
               let httpApi = new XMLHttpRequest();
               httpApi.open('GET',`login?act=reg&userName=${document.querySelector('.user').value}&psd=${document.querySelector('.password').value}`,true);
               httpApi.send();
               httpApi.onreadystatechange = function(res){
                   if(httpApi.readyState == 4){
                       if(httpApi.status ==200){
                      
                           let json =eval("("+httpApi.responseText+")");
                             
                           alert(json.msg);

                       }
                   }
               }
          }
          loginValue.onclick = function (){
              let obj = {
                act:'login',
                ussName:document.querySelector('.user').value,
                psd:document.querySelector('.password').value,
              }
            let httpApi = new XMLHttpRequest();
               httpApi.open('POST',`/user`);
               httpApi.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
               httpApi.send(`act=login&userName=${document.querySelector('.user').value}&psd=${document.querySelector('.password').value}`);
               httpApi.onreadystatechange = function(res){
                   if(httpApi.readyState == 4){
                       if(httpApi.status ==200){
                           let json =eval("("+httpApi.responseText+")");
                             
                           alert(json.msg);

                       }
                   }
               }
          }
    
       </script>

</body>
</html>